import numpy as np

# 定义单应性矩阵 H
H = np.array([
    [0.0426471114, -0.0008612377, -393.0527550794],
    [0.0014097874, 0.0410506353, -334.7324125815],
    [0.0000008465, 0.0000006960, 1]
])

# 定义 8 个点的坐标
points = np.array([
    [12950, 8550], [17750, 8400], [12800, 12250], [18200, 12100], [
        9450, 14400], [21550, 14000], [9650, 20250], [21700, 20000]
])

# 应用单应性变换
transformed_points = []
for point in points:
    # 将点转换为齐次坐标
    point_homogeneous = np.array([point[0], point[1], 1])

    # 应用单应性矩阵
    transformed_point_homogeneous = H @ point_homogeneous

    # 将齐次坐标转换为非齐次坐标
    transformed_point = transformed_point_homogeneous[:2] / \
        transformed_point_homogeneous[2]

    # 将变换后的点添加到列表中
    transformed_points.append(transformed_point)

# 打印变换后的点坐标
for i, point in enumerate(transformed_points):
    print(f"Transformed point {i+1}: {point}")
